package com.atguigu.gmall.list.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.list.service.ListService;
import com.atguigu.gmall.model.list.Goods;
import com.atguigu.gmall.model.list.SearchParam;
import com.atguigu.gmall.model.list.SearchResponseVo;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("api/list")
public class ListApiController {

    @Resource
    private ElasticsearchRestTemplate restTemplate;
    @Resource
    private RestHighLevelClient restHighLevelClient;
    @Resource
    private ListService listService;
    /**
     * @return
     */
    //创建索引  包含Mapping
    @GetMapping("inner/createIndex")
    public Result createIndex() {
        restTemplate.createIndex(Goods.class);
        restTemplate.putMapping(Goods.class);
        return Result.ok();
    }
    //上架
    @GetMapping("/upperGoods/{skuId}")
    public Result upperGoods(@PathVariable Long skuId){
        listService.upperGoods(skuId);
        return Result.ok();
    }
    //下架
    @GetMapping("/lowerGoods/{skuId}")
    public Result lowerGoods(@PathVariable Long skuId){
        listService.lowerGoods(skuId);
        return Result.ok();
    }
    //增加热度 评分
    @GetMapping("/hotScore/{skuId}")
    public Result hotScore(@PathVariable Long skuId){
        listService.hotScore(skuId);
        return Result.ok();
    }
    //开始搜索ES索引库
    @PostMapping("/search")
    public SearchResponseVo search(@RequestBody SearchParam searchParam){
        //高级客户端 ES官方
        //SpringDataEs
        SearchResponseVo vo = listService.search(searchParam);
        return vo;
    }
}
